const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{},
    inpText: '',
    inpName: '',
    inpTitle: '',
    showEdit: false
  },
  changeText: function (e) {
    let name = e.currentTarget.dataset.name;
    let nameMap = {}
    nameMap[name] = e.detail && e.detail.value
    this.setData(nameMap)
  },
  openEdit: function(e){
    console.log(this.data.userInfo)
    let name = e.currentTarget.dataset.name
    this.setData({
      showEdit: true,
      inpTitle: e.currentTarget.dataset.title,
      inpName: name,
      inpText: this.data.userInfo[name]
    })
  },
  cancelBtn: function () {
    this.setData({
      showEdit: false,
      inpTitle: '',
      inpText: ''
    })
  },
  checkBtn: function(){
    var that = this
    let name = this.data.inpName
    let obj = this.data.userInfo
    obj[name] = this.data.inpText
    // this.setData({
    //   userInfo: obj
    // })
    app.req({
      url: "User/CustomerWchat",
      method: "POST",
      data: obj,
      success: function(res){
        if(res.data.Code){
          that.setData({
            userInfo: obj,
            showEdit: false,
            inpTitle: '',
            inpText: '',
            inpName: ''
          })
        }
      }
    })
  },
  getInfo: function () {
    var that = this
    app.req({
      url: 'User/CustomerWchatDetail',
      success: function(res){
        that.setData({
          userInfo:res.data.Result
        })
      }
    })
  },
  logout:function(){
    app.globalData.Authorization = null
    app.globalData.LoginNo = null
    app.globalData.Password = null
    wx.removeStorage({
      key: 'Authorization',
      success: function (res) { },
    })
    wx.removeStorage({
      key: 'LoginNo',
      success: function (res) { },
    })
    wx.removeStorage({
      key: 'Password',
      success: function (res) { },
    })
    wx.reLaunch({
      url: '/pages/user/login/login'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getInfo()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})